s = "tmmzuxt"


class Solution:
    def lengthOfLongestSubstring(self, s: str) -> int:
        if s == "":
            return 0
        ans = 1
        char_index = {}
        i = 0
        char_index[s[0]] = 0

        for j in range(i + 1, len(s)):

            if s[j] in char_index:
                i = max(i, char_index[s[j]] + 1)
                char_index[s[j]] = j
            else:
                char_index[s[j]] = j
            ans = max(ans, j - i + 1)
        return ans


solution = Solution()
result = solution.lengthOfLongestSubstring(s)
print(result)
